using DA.AnimGraph;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

namespace DA.AnimGraph.Editor {
    internal class ResourcesPane : ContextPaneBase {

        HandleKeeper<AGAHandle_Root> rootHK;

        ObjectField objField;

        AGA_Resources.Entry target;

        public ResourcesPane(ContextPaneBase parent) : base(parent) {
            //objField = new ObjectField("obj");
            //objField.objectType = typeof(AnimationClip);
            //objField.RegisterValueChangedCallback((evt) => {
            //    objField.value = evt.newValue;
            //    if (evt.previousValue == null) {
            //        rootHK.handle.AddResourceEntry(evt.newValue, ResourcesType.Clip);
            //    }else {
            //        target.resource = evt.newValue;
            //        rootHK.handle.ModifyResourceEntry(target.uuid, target);
            //    }
            //});
        }

        protected override void OnSetHandle(AGAHandleBase handle) {
            Debug.Assert(handle is AGAHandle_Root || handle == null);
            if (handle == null) {
                rootHK = default;
                return;
            }
            rootHK = new HandleKeeper<AGAHandle_Root>(handle as AGAHandle_Root);
        }

        protected override void OnClearUI() {
            Clear();
        }

        protected override void OnDrawUI() {
            //if (rootHK.handle.resourcesEntries.Count == 0) {
            //    objField.value = null;
            //} else {
            //    target = rootHK.handle.resourcesEntries.First();
            //    objField.value = target.resource;
            //}
            //Add(objField);
        }
    }
}
